/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.TableView
 *  javafx.scene.layout.AnchorPane
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.salesReceipts.GetQueryMemberOutData;
import com.gys.data.salesReceipts.GetSalesReceiptsTableOutData;
import de.felixroske.jfxsupport.FXMLController;
import java.math.BigDecimal;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class RestPriceController
extends BaseController
implements Initializable {
    @FXML
    private AnchorPane pane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
    }

    @FXML
    private void sureAction() {
        TableView<GetSalesReceiptsTableOutData> tableView = this.salesReceiptsMainController.getTableView();
        String disc = "100";
        GetQueryMemberOutData memberOutData = (GetQueryMemberOutData)CacheUtil.get("memberOutData");
        if (ObjectUtil.isNotEmpty(memberOutData)) {
            disc = memberOutData.getDis();
        }
        for (int i = 0; i < tableView.getItems().size(); ++i) {
            GetSalesReceiptsTableOutData item = (GetSalesReceiptsTableOutData)tableView.getItems().get(i);
            item.setDisc(disc);
            item.setNum("1");
            if ("\u62c6\u96f6".equals(item.getStatus())) {
                item.setPrcAmount(item.getPrcAmountD());
            }
            BigDecimal price = new BigDecimal(item.getPrcAmount()).divide(new BigDecimal(100)).multiply(new BigDecimal(disc));
            item.setPrice(CommonUtil.bigDecimalTo2fStr(price));
            BigDecimal totalPrice = new BigDecimal(item.getNum()).multiply(price);
            item.setTotal(CommonUtil.bigDecimalTo2fStr(totalPrice));
            if (ObjectUtil.isEmpty(memberOutData)) {
                item.setStatus("\u6b63\u5e38");
                continue;
            }
            item.setStatus("\u4f1a\u5458\u5361\u6298\u6263");
        }
        tableView.refresh();
        this.salesReceiptsMainController.countMoney();
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

